package service.impl;

import dao.UserDao;
import dao.impl.UserDaoImpl;
import entity.User;
import service.UserService;

import java.util.List;

public class UserServiceImpl implements UserService {
    UserDao userDao = new UserDaoImpl();

    @Override
    public int addUser(User user) {
        return userDao.addUser(user);
    }

    @Override
    public User login(String discount, String password) {
        return userDao.login(discount,password);
    }

    @Override
    public int retrievePassword(String phone, String discount, String password) {
        boolean flag = userDao.findByPhone(phone);
        if(flag){
            return userDao.updatePassword(discount,password,phone);
        }else{
            return -1;
        }
    }

    @Override
    public int updateUser(String headImg, String username, String address, int id) {
        return userDao.updateUser(headImg,username,address,id);
    }

    @Override
    public List<User> findAll() {
        return userDao.findAll();
    }

    @Override
    public List<User> findAllByName(String name) {
        return userDao.findAllByName(name);
    }

    @Override
    public int addAll(User user) {
        return userDao.addAll(user);
    }

    @Override
    public int updateById(User user) {
        return userDao.updateById(user);
    }

    @Override
    public int delById(int id) {
        return userDao.delById(id);
    }

    @Override
    public User findId(int id) {
        return userDao.findId(id);
    }
}
